#ifndef _DEFINE_EPOLLCLIENT_H_
#define _DEFINE_EPOLLCLIENT_H_
#define _MAX_SOCKFD_COUNT 65535

#include <iostream>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <pthread.h>
#include <string>

using namespace std;

/**
*@user status
*/
typedef enum _EPOLL_USER_STATUS_EM
{
    FREE = 0,
    CONNECT_OK = 1,
    SEND_OK = 2,
    RECV_OK = 3,
}EPOLL_USER_STATUS_EM;

struct UserStatus
{
    EPOLL_USER_STATUS_EM iUserStatus;
    int iSockFd;
    char cSendbuff[1024];
    int iBuffLen;
    unsigned int uEpollEvents;
};

class CEpollClient
{
public:
    CEpollClient(int iUserCount, const char* pIP, int iPort);
    ~CEpollClient();

    int RunFun();

private:
    int ConnectToServer(int iUserId, const char* pServerIp, unsigned short uServerPort);
    int SendToServerData(int iUserId);
    int RecvFromServer(int iUserId, char* pRecvBuff, int iBuffLen);
    bool CloseUser(int iUserId);
    bool DelEpoll(int iSockFd);

private:
    int m_iUserCount;
    struct UserStatus *m_pAllUserStatus;
    int m_iEpollFd;
    int m_iSockFd_UserId[_MAX_SOCKFD_COUNT];
    int m_iPort;
    char m_ip[100];
};

#endif
